package com.yunchao.bank.main.domain.repository

import com.yunchao.bank.business.domain.model.BusinessInfoModel
import com.yunchao.bank.main.data.model.MetadataUserModel
import com.yunchao.library.socket.config.Message
import com.yunchao.library.socket.config.MessageHeader
import com.yunchao.library.socket.model.card.CommandData
import kotlinx.coroutines.flow.Flow

internal interface NavHostRepository {

    /* 设备相关操作 */
    suspend fun openDevice(): Result<Boolean>
    suspend fun closeDevice()


    /**
     * 处理接收到的消息
     */
    suspend fun processIncomingMessage(message: Message): ByteArray?

    /**
     * 消息加密
     */
    suspend fun processEncryption(header: MessageHeader, bytes: ByteArray): ByteArray


    /**
     * 观察接收到的拍卡消息
     * @return Flow<String>
     */
//    fun observeCardMessage(): Flow<MetadataUserModel?>

    /**
     * 观察接收到的错误消息
     * @return Flow<String>
     */
    fun observeSocketError(): Flow<SocketErrorMessage>


    fun observeBusinessInfo(): Flow<BusinessInfoModel>

    suspend fun handleCardCommand(commandData: CommandData): Result<MetadataUserModel?>

    suspend fun sendCardCommand(isDelay: Boolean = false)
}

sealed class SocketErrorMessage{
    data class Error(val message: String): SocketErrorMessage()
    data class Warning(val message: String): SocketErrorMessage()
    data class Success(val message: String): SocketErrorMessage()
}
